class Solution(object):
    def numsSameConsecDiff(self, n, k):
        out = []

        def search(i, num):
            if i == n:
                out.append(num)
            else:
                last = num % 10
                num *= 10
                if k == 0:
                    search(i + 1, num + last)
                else:
                    if last + k <= 9:
                        search(i + 1, num + last + k)
                    if last - k >= 0:
                        search(i + 1, num + last - k)

        for i in range(1, 10):
            search(1, i)

        return out


data = Solution()
n = 3
k = 7
print(data.numsSameConsecDiff(n, k))
